import axios from '@/axios' //这是引入axios实例

// function方法导出
// export function login (username, password) {
//   return axios.post('/admin/login', {
//     username,
//     password
//   })
// }

// 箭头函数导出
export const login = (username, password) => {
  return axios.post('/admin/login', {
    username,
    password
  })
}
// 获取用户信息
export const getinfo = () => {
  return axios.post('/admin/getinfo')
}
// 退出登录
// export const logout = () => {
//   return axios.post('/admin/logout')
// }
// 简化写法
export const logout = () => axios.post('/admin/logout')
// 修改密码
export const updatepassword = data => axios.post('/admin/updatepassword', data)

export function getManagerList (page, query = {}) {
  let q = []
  for (const key in query) {
    if (query[key]) {
      q.push(`${key}=${encodeURIComponent(query[key])}`)
    }
  }
  let r = q.join('&')
  r = r ? '?' + r : ''

  return axios.get(`/admin/manager/${page}${r}`)
}

export function updateManagerStatus (id, status) {
  return axios.post(`/admin/manager/${id}/update_status`, {
    status
  })
}

export function createManager (data) {
  return axios.post(`/admin/manager`, data)
}

export function updateManager (id, data) {
  return axios.post(`/admin/manager/${id}`, data)
}

export function deleteManager (id) {
  return axios.post(`/admin/manager/${id}/delete`)
}
